package FreeCellDataStructures;

import java.util.LinkedList;
import java.util.List;
import FreeCellBackend.Card;

public class Cascade {
	private List<OrderedCascade> cascade;
	
	public Cascade(){
		cascade = new LinkedList<OrderedCascade>();
	}
	public boolean add(OrderedCascade oc, boolean fromDeck){
		//Checks new cascade to see if we should just add the two together
		if(cascade.get(cascade.size()-1).getTop().getValue() - 1 == oc.getBottom().getValue())
			if(cascade.get(cascade.size()-1).getTop().getSuite() % 2 != oc.getBottom().getSuite() % 2){
				cascade.get(cascade.size()-1).consolidate(oc);
				return true;
			}
		if(fromDeck)
			return cascade.add(oc);
		return false;
	}
	
	public OrderedCascade remove(int index){
		if(cascade.get(cascade.size()-1).size()<=index)
			return cascade.get(cascade.size()-1).remove(index);
		return null;
	}
	public List<Card> getCascade(){
		List<Card> temp = null;
		for(OrderedCascade oc: cascade)
			for(int i=0; i<oc.size()-1; i++)
				temp.add(oc.getOrderedCascadeCards(i));
		return temp;
	}
}
